#!/bin/bash
#this generates xml code for a gtkdialog gui.
#it is NOT a standalone window
#
#the reason for using this template is to control icon-height for all buttons in all apps by setting HEIGHT here
#
#usage :
# xml_button-icon ICON SIZE
#
# ICON can either be a gtk stock icon, a normal raster/vector file or no icon. if no path is set, /usr/share/pixmaps/puppy/ is used
# SIZE can be popup, mini, big or huge. Anything else sets size to buttonsize
#
#Sigmund Berglund, dec 2013
#GPL

#either use Puppy-stock icons (puppy) or Gtk-stock icons (gtk)
#STOCK=puppy
STOCK=gtk

#define icon
case $1 in
	/*svg)
		#icon from svg file
		ICON="<input file>${1}</input>"
		;;
	*.svg)
		#icon from puppy stock
		ICON="<input file>/usr/share/pixmaps/puppy/${1}</input>"
		;;
	/*)
		#icon from file
		ICON="<input file>${1}</input>"
		;;
	0|none|' '|'')
		ICON=""
		;;
	gtk-*)
		ICON="<input file stock=\"${1}\"></input>"
		;;
	*) 
		#stock icon - use either Gtk-stock or Puppy-stock
		if [ "$STOCK" = "puppy" ]; then
			if [ -s "/usr/share/pixmaps/puppy/${1}.svg" ]; then
				ICON="<input file>/usr/share/pixmaps/puppy/${1}.svg</input>"
			else
				ICON="<input file stock=\"gtk-${1}\"></input>"
			fi
		else
			#We have to check if icon is a part of active gtk-theme - if not, use Puppy stock
			if [ "$(find /usr/share/icons/ -iname "*${1}*")" ]; then #gtk icon themes
				ICON="<input file stock=\"gtk-${1}\"></input>"
			else
				ICON="<input file>/usr/share/pixmaps/puppy/${1}.svg</input>"
			fi
		fi
esac

#read config if exist
[ -s $HOME/.config/ptheme/gtkdialog_active ] && . $HOME/.config/ptheme/gtkdialog_active
[ ! "$XML_BUTTON_ICON_HEIGHT_HUGE" ]	&& XML_BUTTON_ICON_HEIGHT_HUGE=60
[ ! "$XML_BUTTON_ICON_HEIGHT_BIG" ]		&& XML_BUTTON_ICON_HEIGHT_BIG=35
[ ! "$XML_BUTTON_ICON_HEIGHT_MINI" ]	&& XML_BUTTON_ICON_HEIGHT_MINI=16
[ ! "$XML_BUTTON_ICON_HEIGHT_NORMAL" ]	&& XML_BUTTON_ICON_HEIGHT_NORMAL=20

if [ "$ICON" ]; then
	case $2 in
		huge)
			HEIGHT="<height>${XML_BUTTON_ICON_HEIGHT_HUGE}</height>"
			;;
		big)
			HEIGHT="<height>${XML_BUTTON_ICON_HEIGHT_BIG}</height>"
			;;
		mini)
			HEIGHT="<height>${XML_BUTTON_ICON_HEIGHT_MINI}</height>"
			;;
		*)
			HEIGHT="<height>${XML_BUTTON_ICON_HEIGHT_NORMAL}</height>"
			;;
	esac
fi
	
#generate XML code
echo "$ICON $HEIGHT"
